package com.lifu.yygh.user.api;

import com.lifu.yygh.common.result.Result;
import com.lifu.yygh.common.utils.AuthContextHolder;
import com.lifu.yygh.model.user.UserInfo;
import com.lifu.yygh.user.service.UserInfoService;
import com.lifu.yygh.vo.user.LoginVo;
import com.lifu.yygh.vo.user.UserAuthVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Description
 * @Author lifu
 * @Date 2021/5/18 20:55
 */
@Api(tags = "用户信息接口")
@RestController
@RequestMapping(value = "/api/user")
public class UserInfoApiController {
    @Autowired
    private UserInfoService userInfoService;

    //用户手机号登录接口
    @ApiOperation(value = "用户手机号登录接口")
    @PostMapping(value = "/login")
    public Result login(@RequestBody LoginVo loginVo){
        Map<String,Object> info = userInfoService.loginUser(loginVo);
        return Result.ok(info);
    }
    //用户认证的接口
    @ApiOperation(value = "用户认证的接口")
    @PostMapping(value = "/auth/userAuth")
    public Result userAuth(@RequestBody UserAuthVo userAuthVo, HttpServletRequest httpServletRequest){
        userInfoService.userAuth(AuthContextHolder.getUserId(httpServletRequest),userAuthVo);
        return Result.ok();
    }
    //获取用户id信息接口
    @ApiOperation(value = "获取用户id信息接口")
    @GetMapping(value = "/auth/getUserInfo")
    public Result getUserInfo(HttpServletRequest httpServletRequest){
        Long userId = AuthContextHolder.getUserId(httpServletRequest);
        UserInfo userInfo = userInfoService.getById(userId);
        return Result.ok(userInfo);
    }

}
